<div id="district-detail" class="modal fade">
  <div class="modal-dialog" >
    <div class="modal-content">
    	<div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
          <h4 class="modal-title">新增小区</h4>
      </div>
      <div class="modal-body">
				<div class="row">
					<form id="districtForm" action='{:U("Admin/District/updateDistrict")}' method="post">
					<div class="form-group">
						<div class="col-sm-12">
							<div class="col-sm-1"></div>
							<div class="col-sm-3" style="padding-left:15px;padding-top:5px">
								<label for="index" class="control-label">选择仓库：</label>
							</div>
							<div class="col-sm-6">
								<input id="district_id" name="district_id" class="form-control" style="display:none;"></input>
								<ul id="repositoryTree1" class="ztree"></ul>
							</div>
						</div>
				  	<div class="col-sm-12">
				  		<div class="col-sm-1"></div>
					    <div class="col-sm-3" style="padding-left:15px;padding-top:5px">
								<label for="index" class="control-label">排序：</label>
							</div>
							<div class="col-sm-6">
								<input id="index" name="index" class="form-control"></input>
							</div>
						</div>
						<div class="col-sm-12">
				  		<br>
				  		<div class="col-sm-1"></div>
					    <div class="col-sm-3" style="padding-left:15px;padding-top:5px">
								<label for="name" class="control-label">小区名称：</label>
							</div>
							<div class="col-sm-6">
								<input id="name" name="name" class="form-control"></input>
							</div>
						</div>
						<div class="col-sm-12">
				  		<br>
				  		<div class="col-sm-1"></div>
				    <div class="col-sm-3" style="padding-left:15px;padding-top:5px">
							<label for="address" class="control-label">小区地址：</label>
						</div>
						<div class="col-sm-6">
							<input id="address" name="address" class="form-control"></input>
						</div>
						</div>
						<div class="col-sm-12">
				  		<br>
				  		<div class="col-sm-1"></div>
					    <div class="col-sm-3" style="padding-left:15px;padding-top:5px">
								<label for="region" class="control-label">所属区：</label>
							</div>
							<div class="col-sm-6">
								<input id="region" name="region" class="form-control"></input>
							</div>
						</div>
				    	<br><br>
					</div>
					</form>
				</div>
			</div>
			<div class="modal-footer">
        <button class="btn btn-primary" onclick="submit()">保存</button>
        <button class="btn btn-defalt" data-dismiss="modal">取消</button>
    	</div>
		</div>
	</div>
</div>
<script>
$('#district-detail').on("hidden.bs.modal",function(e){
		var treeObj = $.fn.zTree.getZTreeObj("repositoryTree1");
		treeObj.cancelSelectedNode();
    $("input[name='district_id']").attr('value', '');
    $("input[name='name']").attr('value',"");
    $("input[name='region']").attr('value', '');
    $("input[name='address']").attr('value', '');
    $("input[name='index']").attr('value', '');
}); 

function submit(){
	var treeObj = $.fn.zTree.getZTreeObj("repositoryTree1");
	var nodes = treeObj.getSelectedNodes();
	if(nodes.length == 0 || typeof(nodes[0].a_repository_id) == 'undefined'){
		alert("请选择一个A仓库！");
		return;
	}
	var a_repository_id = nodes[0].a_repository_id;

  $('#districtForm').ajaxSubmit({
  		data: {
        'a_repository_id': a_repository_id
      },
      success:function(data){
          $('#districtForm').modal('hide');
          location.reload();
      }
  });
}
	
</script>